package com.ourteam.workspace.dao.impl;

import com.ourteam.workspace.dao.IWorkspaceResourceBusinessPackageRelateDAO;
import com.ourteam.workspace.dao.WorkspaceResourceBusinessPackageRelate;
import com.ourteam.workspace.dao.WorkspaceResourceBusinessPackageRelateDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-11-30 18:42:33 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractWorkspaceResourceBusinessPackageRelateDAOJdbcImpl extends AbstractSpringDAO
    implements IWorkspaceResourceBusinessPackageRelateDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {
        Id,
        BusinessPcakageId,
        Description,
        Status,
        WorkspaceResourceId,
        LastGenCodeTime,
        SubmitterId,
        SubmitterName,
        ResourceName,
        ResourceType,
        ResourcePath,
        WorkspaceId,
        ResourceOrderIndex,
        BusinessPackageName,
        BusinessPackageType,
        BusinessDomainId,
        BusinessDomainName
      };

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.BusinessPcakageId,
        _DataObjectProperty.Description,
        _DataObjectProperty.Status,
        _DataObjectProperty.WorkspaceResourceId,
        _DataObjectProperty.LastGenCodeTime,
        _DataObjectProperty.SubmitterId,
        _DataObjectProperty.SubmitterName,
        _DataObjectProperty.ResourceName,
        _DataObjectProperty.ResourceType,
        _DataObjectProperty.ResourcePath,
        _DataObjectProperty.WorkspaceId,
        _DataObjectProperty.ResourceOrderIndex,
        _DataObjectProperty.BusinessPackageName,
        _DataObjectProperty.BusinessPackageType,
        _DataObjectProperty.BusinessDomainId,
        _DataObjectProperty.BusinessDomainName
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<
          WorkspaceResourceBusinessPackageRelate,
          WorkspaceResourceBusinessPackageRelateDAOQueryBean>
      daoHelper;

  public AbstractWorkspaceResourceBusinessPackageRelateDAOJdbcImpl() {
    super();
    daoHelper =
        new DataAccessObjectHelper<
            WorkspaceResourceBusinessPackageRelate,
            WorkspaceResourceBusinessPackageRelateDAOQueryBean>(this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.workspace.dao.IWorkspaceResourceDAO.EntityName)
          .append(" RELATED_3CDJZY_WorkspaceResource ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.workspace.dao.IWorkspaceResourceDAO.Id,
              com.ourteam.workspace.dao.IWorkspaceResourceDAO.EntityName + ".",
              "RELATED_3CDJZY_WorkspaceResource."));
      relatedJoinSQLBuffer.append(" = ").append(WorkspaceResourceId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.product.model.dao.IProductModelPackageDAO.EntityName)
          .append(" Product_Model_Package ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.product.model.dao.IProductModelPackageDAO.Id,
              com.ourteam.product.model.dao.IProductModelPackageDAO.EntityName + ".",
              "Product_Model_Package."));
      relatedJoinSQLBuffer.append(" = ").append(BusinessPcakageId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.product.model.dao.IProductModelDomainDAO.EntityName)
          .append(" product_model_domain ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.product.model.dao.IProductModelDomainDAO.Id,
              com.ourteam.product.model.dao.IProductModelDomainDAO.EntityName + ".",
              "product_model_domain."));
      relatedJoinSQLBuffer.append(" = ").append(BusinessDomainId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aWorkspaceResourceBusinessPackageRelate
   * @throws Exception
   */
  public boolean checkIsUnique(
      WorkspaceResourceBusinessPackageRelate aWorkspaceResourceBusinessPackageRelate)
      throws Exception {

    if (aWorkspaceResourceBusinessPackageRelate == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aWorkspaceResourceBusinessPackageRelate.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aWorkspaceResourceBusinessPackageRelate
   * @throws Exception
   */
  public void insert(WorkspaceResourceBusinessPackageRelate aWorkspaceResourceBusinessPackageRelate)
      throws Exception {

    super.doInsert(aWorkspaceResourceBusinessPackageRelate);
  }

  /**
   * Batch Insert Datas
   *
   * @param aWorkspaceResourceBusinessPackageRelate
   * @throws Exception
   */
  public void batchInsert(
      WorkspaceResourceBusinessPackageRelate[] aWorkspaceResourceBusinessPackageRelates)
      throws Exception {

    super.doBatchInsert(aWorkspaceResourceBusinessPackageRelates);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(WorkspaceResourceBusinessPackageRelateDAOQueryBean queryBean)
      throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(WorkspaceResourceBusinessPackageRelate aWorkspaceResourceBusinessPackageRelate)
      throws Exception {

    delete(aWorkspaceResourceBusinessPackageRelate.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aWorkspaceResourceBusinessPackageRelate
   * @throws Exception
   */
  public void update(WorkspaceResourceBusinessPackageRelate aWorkspaceResourceBusinessPackageRelate)
      throws Exception {

    if (aWorkspaceResourceBusinessPackageRelate.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aWorkspaceResourceBusinessPackageRelate);

    WorkspaceResourceBusinessPackageRelate tempObj =
        findById(aWorkspaceResourceBusinessPackageRelate.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aWorkspaceResourceBusinessPackageRelate, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aWorkspaceResourceBusinessPackageRelates[]
   * @throws Exception
   */
  public void batchUpdate(
      WorkspaceResourceBusinessPackageRelate[] aWorkspaceResourceBusinessPackageRelates)
      throws Exception {

    super.doBatchUpdate(aWorkspaceResourceBusinessPackageRelates);
  }

  /**
   * Update Data By Condictions
   *
   * @param aWorkspaceResourceBusinessPackageRelate
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(
      WorkspaceResourceBusinessPackageRelate aWorkspaceResourceBusinessPackageRelate,
      WorkspaceResourceBusinessPackageRelateDAOQueryBean aQueryBean)
      throws Exception {

    super.doUpdateByQuery(aWorkspaceResourceBusinessPackageRelate, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(WorkspaceResourceBusinessPackageRelateDAOQueryBean aQueryBean)
      throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(
      WorkspaceResourceBusinessPackageRelate aWorkspaceResourceBusinessPackageRelate)
      throws Exception {

    if (aWorkspaceResourceBusinessPackageRelate.getDescription() == null) {
      throw new Exception(
          "The WorkspaceResourceBusinessPackageRelate.description value is not allow NULL");
    }

    if (aWorkspaceResourceBusinessPackageRelate.getStatus() == null) {
      throw new Exception(
          "The WorkspaceResourceBusinessPackageRelate.status value is not allow NULL");
    }
  }

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public WorkspaceResourceBusinessPackageRelate findById(final long id) throws Exception {

    WorkspaceResourceBusinessPackageRelateDAOQueryBean queryBean =
        new WorkspaceResourceBusinessPackageRelateDAOQueryBean();

    WorkspaceResourceBusinessPackageRelateDAOQueryBean.Criteria criteria =
        queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    WorkspaceResourceBusinessPackageRelate[] WorkspaceResourceBusinessPackageRelates =
        query(queryBean);

    if (WorkspaceResourceBusinessPackageRelates.length == 0) {
      return null;
    } else {
      return WorkspaceResourceBusinessPackageRelates[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return WorkspaceResourceBusinessPackageRelate[]
   * @throws Exception
   */
  public WorkspaceResourceBusinessPackageRelate[] query(
      WorkspaceResourceBusinessPackageRelateDAOQueryBean queryBean) throws Exception {

    List result =
        super.doQuery(queryBean, new JdbcWorkspaceResourceBusinessPackageRelateRowMapper());

    return (WorkspaceResourceBusinessPackageRelate[])
        result.toArray(new WorkspaceResourceBusinessPackageRelate[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(
      WorkspaceResourceBusinessPackageRelateDAOQueryBean queryBean) throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(WorkspaceResourceBusinessPackageRelateDAOQueryBean queryBean)
      throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(
      WorkspaceResourceBusinessPackageRelate[] aWorkspaceResourceBusinessPackageRelates,
      WorkspaceResourceBusinessPackageRelateDAOQueryBean queryBean)
      throws Exception {
    daoHelper.synchronize(aWorkspaceResourceBusinessPackageRelates, queryBean);
  }

  public void synchronize(
      WorkspaceResourceBusinessPackageRelate[] aWorkspaceResourceBusinessPackageRelates,
      WorkspaceResourceBusinessPackageRelateDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<WorkspaceResourceBusinessPackageRelate>
          callBack)
      throws Exception {
    daoHelper.synchronize(aWorkspaceResourceBusinessPackageRelates, queryBean, callBack);
  }

  public static class JdbcWorkspaceResourceBusinessPackageRelateRowMapper
      implements RowMapper<WorkspaceResourceBusinessPackageRelate> {

    public WorkspaceResourceBusinessPackageRelate mapRow(ResultSet resultSet, int arg1)
        throws SQLException {
      WorkspaceResourceBusinessPackageRelate object = new WorkspaceResourceBusinessPackageRelate();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object businessPcakageId = null;

        businessPcakageId = resultSet.getObject(columnIndex++);

        object.setBusinessPcakageIdNull(resultSet.getBoolean(columnIndex++));

        if (businessPcakageId != null) {

          setBeanValue(object, _DataObjectProperty.BusinessPcakageId, businessPcakageId);
        }

        Object description = null;

        description = resultSet.getObject(columnIndex++);

        object.setDescriptionNull(resultSet.getBoolean(columnIndex++));

        if (description != null) {

          setBeanValue(object, _DataObjectProperty.Description, description);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object workspaceResourceId = null;

        workspaceResourceId = resultSet.getObject(columnIndex++);

        object.setWorkspaceResourceIdNull(resultSet.getBoolean(columnIndex++));

        if (workspaceResourceId != null) {

          setBeanValue(object, _DataObjectProperty.WorkspaceResourceId, workspaceResourceId);
        }

        Object lastGenCodeTime = null;

        __dataType = resultSet.getMetaData().getColumnType(columnIndex);

        if (__dataType == java.sql.Types.DATE
            || __dataType == java.sql.Types.TIME
            || __dataType == java.sql.Types.TIMESTAMP) {
          lastGenCodeTime = resultSet.getTimestamp(columnIndex++);

        } else {
          lastGenCodeTime = resultSet.getObject(columnIndex++);
        }

        object.setLastGenCodeTimeNull(resultSet.getBoolean(columnIndex++));

        if (lastGenCodeTime != null) {

          setBeanValue(object, _DataObjectProperty.LastGenCodeTime, lastGenCodeTime);
        }

        Object submitterId = null;

        submitterId = resultSet.getObject(columnIndex++);

        object.setSubmitterIdNull(resultSet.getBoolean(columnIndex++));

        if (submitterId != null) {

          setBeanValue(object, _DataObjectProperty.SubmitterId, submitterId);
        }

        Object submitterName = null;

        submitterName = resultSet.getObject(columnIndex++);

        object.setSubmitterNameNull(resultSet.getBoolean(columnIndex++));

        if (submitterName != null) {

          setBeanValue(object, _DataObjectProperty.SubmitterName, submitterName);
        }

        Object resourceName = null;

        resourceName = resultSet.getObject(columnIndex++);

        object.setResourceNameNull(resultSet.getBoolean(columnIndex++));

        if (resourceName != null) {

          setBeanValue(object, _DataObjectProperty.ResourceName, resourceName);
        }

        Object resourceType = null;

        resourceType = resultSet.getObject(columnIndex++);

        object.setResourceTypeNull(resultSet.getBoolean(columnIndex++));

        if (resourceType != null) {

          setBeanValue(object, _DataObjectProperty.ResourceType, resourceType);
        }

        Object resourcePath = null;

        resourcePath = resultSet.getObject(columnIndex++);

        object.setResourcePathNull(resultSet.getBoolean(columnIndex++));

        if (resourcePath != null) {

          setBeanValue(object, _DataObjectProperty.ResourcePath, resourcePath);
        }

        Object workspaceId = null;

        workspaceId = resultSet.getObject(columnIndex++);

        object.setWorkspaceIdNull(resultSet.getBoolean(columnIndex++));

        if (workspaceId != null) {

          setBeanValue(object, _DataObjectProperty.WorkspaceId, workspaceId);
        }

        Object resourceOrderIndex = null;

        resourceOrderIndex = resultSet.getObject(columnIndex++);

        object.setResourceOrderIndexNull(resultSet.getBoolean(columnIndex++));

        if (resourceOrderIndex != null) {

          setBeanValue(object, _DataObjectProperty.ResourceOrderIndex, resourceOrderIndex);
        }

        Object businessPackageName = null;

        businessPackageName = resultSet.getObject(columnIndex++);

        object.setBusinessPackageNameNull(resultSet.getBoolean(columnIndex++));

        if (businessPackageName != null) {

          setBeanValue(object, _DataObjectProperty.BusinessPackageName, businessPackageName);
        }

        Object businessPackageType = null;

        businessPackageType = resultSet.getObject(columnIndex++);

        object.setBusinessPackageTypeNull(resultSet.getBoolean(columnIndex++));

        if (businessPackageType != null) {

          setBeanValue(object, _DataObjectProperty.BusinessPackageType, businessPackageType);
        }

        Object businessDomainId = null;

        businessDomainId = resultSet.getObject(columnIndex++);

        object.setBusinessDomainIdNull(resultSet.getBoolean(columnIndex++));

        if (businessDomainId != null) {

          setBeanValue(object, _DataObjectProperty.BusinessDomainId, businessDomainId);
        }

        Object businessDomainName = null;

        businessDomainName = resultSet.getObject(columnIndex++);

        object.setBusinessDomainNameNull(resultSet.getBoolean(columnIndex++));

        if (businessDomainName != null) {

          setBeanValue(object, _DataObjectProperty.BusinessDomainName, businessDomainName);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
